<template>
  <div class="header">
    <div class="left">
    </div>
    <div class="right">
      <el-avatar :src="userInfo.avatar" style="margin-right: 10px"/>
      <el-dropdown>
        <span>
            {{ userInfo.username }}<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
        <el-dropdown-menu v-slot="dropdown">
          <el-dropdown-item @click.native="logout">退出登录</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
import {logout as logoutApi } from "@/api/LoginApi";

export default {
  data() {
    return {
      userInfo: JSON.parse(localStorage.getItem("userInfo"))
    }
  },
  methods: {
    logout() {
      logoutApi().then(res => {
        window.localStorage.clear();
        this.$router.push('/login')
        this.$message.success("退出成功")
      })
    }
  }
}
</script>

<style scoped lang="scss">
.header {
  display: flex;
  height: 64px;
  align-items: center;
  justify-content: space-between;
  //box-shadow: 0 2px 4px rgba(0, 0, 0, .08);
  box-shadow: 0 1px 4px rgba(0, 21, 41, .08);

}


.right {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin-right: 20px;
  height: 100%;
}
</style>
